package com.tengfei.sharedpreferencesdemo;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class ShowActivity extends AppCompatActivity {

    private EditText mEt_3;
    private Button mBt_3;
    private TextView mTv_1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);

        init();
        click();

    }

    private void click() {
        mBt_3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String key = mEt_3.getText().toString().trim();
                if (TextUtils.equals(key, "")) {
                    Toast.makeText(ShowActivity.this, "请输入信息", Toast.LENGTH_SHORT).show();
                } else {
                    SharedPreferences spf = getSharedPreferences("myShare", MODE_PRIVATE);
                    String value = spf.getString(key, "");
                    mTv_1.setText(value);
                    Toast.makeText(ShowActivity.this, "获取成功", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private void init() {
        mEt_3 = findViewById(R.id.et_3);
        mBt_3 = findViewById(R.id.bt_3);
        mTv_1 = findViewById(R.id.tv_1);
    }
}